var audioElements = document.getElementsByTagName("audio"),
  sounds = {};
console.log(1111, audioElements);

for (var i = 0; i < audioElements.length; i++) {
  sounds[audioElements[i].className] = audioElements[i];
}
if (mediaPlaybackRequiresUserGesture()) {
  window.addEventListener("keydown", removeBehaviorsRestrictions);
  window.addEventListener("mousedown", removeBehaviorsRestrictions);
  window.addEventListener("touchstart", removeBehaviorsRestrictions);
}

function mediaPlaybackRequiresUserGesture() {
  // test if play() is ignored when not called from an input event handler
  var video = document.createElement("video");
  video.play();
  return video.paused;
}

function removeBehaviorsRestrictions() {
  for (var i = 0; i < audioElements.length; i++) {
    audioElements[i].load();
  }

  window.removeEventListener("keydown", removeBehaviorsRestrictions);
  window.removeEventListener("mousedown", removeBehaviorsRestrictions);
  window.removeEventListener("touchstart", removeBehaviorsRestrictions);
}

function playSound(sound) {
  var audioElements = document.getElementsByTagName("audio"),
    sounds = {};
  console.log(1111, audioElements);

  for (var i = 0; i < audioElements.length; i++) {
    sounds[audioElements[i].className] = audioElements[i];
  }
  for (var key in sounds) {
    sounds[key].pause();
  }
  console.log(sounds);
  sounds[sound].load();
  sounds[sound].play();
}

module.exports = {
  playSound: playSound
};
